package group2assignone.view;

import javax.swing.table.AbstractTableModel;
import java.util.*;
/**
 *this class extends the abstractTableModel
 * it is designed to hold a listing of all the manager in the database
 * it is a table with selectable rows, text in no editable
 * @author group2
 */
public class ClientTable extends AbstractTableModel{

    private String[] columnNames = {"Username", "Password"};
    private String[][] data = null;

    public ClientTable(ArrayList<String> clientList) {
        int row = 0;
        if (!(clientList == null)) {
            data = new String[clientList.size()][columnNames.length];

            for (String s : clientList) {
                String[] temp = s.split(",");
                String uName = temp[0];
                String pWord = temp[1];

                int column = 0;
                data[row][column] = uName;
                column++;
                data[row][column] = pWord;
                column++;
                row++;
            }
        }
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        if(data != null){
        return data.length;
        }
        else{
            return 0;
        }
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public String getValueAt(int row, int col) {
        return data[row][col];
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(String value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }

}


